package com.gexin.common.kusy;

import com.jfinal.kit.HashKit;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class KusyUtil {
    /*接口域名*/
    public static String Api_Url = "http://api2.lfwin.com";
    /*apikey,唯一标识*/
    public static String Api_key = "14021801";
    /*签名加密key*/
    public static String Sign_Key = "70761079";
    /*微信支付随机字符串*/
    public static String Nonce_Str = "gexin";

    public enum AccountType {
        PERSONAL_WECHATID,MERCHANT_ID
    }

    /**
     * 签名
     * @param params        签名参数
     * @param key           加密key
     * @return
     */
    public static String createSign(Map<String,String> params,String key){
        params.remove("sign");
        StringBuffer sb = new StringBuffer();
        Set es = params.entrySet();
        Iterator it = es.iterator();
        while(it.hasNext()) {
            Map.Entry entry = (Map.Entry)it.next();
            String k = (String)entry.getKey();
            Object v = entry.getValue();
            sb.append(k + "=" + v + "&");

        }
        sb.append("signkey="+key);
        //MD5签名
        System.out.println(sb.toString());
        String sign = HashKit.md5(sb.toString());
        return sign.toLowerCase();
    }
}
